import request from '@/utils/request'

export interface ItemDTO {
  id?: number
  name: string
  price: number
  stock: number
  image: string
  category: string
  brand: string
  spec: string
  sold: number
  commentCount: number
  isAD: boolean
  status: number
  createTime?: string
  updateTime?: string
  creater?: number
  updater?: number
}

export interface ItemPageQuery {
  pageNo: number
  pageSize: number
  key?: string
  brand?: string
  category?: string
  minPrice?: number
  maxPrice?: number
}

// 获取商品列表
export const getItemList = (params: ItemPageQuery) => {
  return request({
    url: '/search/list',
    method: 'get',
    params
  })
}

// 根据id查询商品
export const getItemById = (id: number) => {
  return request({
    url: `/items/${id}`,
    method: 'get'
  })
}

// 新增商品
export const createItem = (data: ItemDTO) => {
  return request({
    url: '/items',
    method: 'post',
    data
  })
}

// 更新商品
export const updateItem = (data: ItemDTO) => {
  return request({
    url: '/items',
    method: 'put',
    data
  })
}

// 更新商品状态
export const updateItemStatus = (id: number, status: number) => {
  return request({
    url: `/items/status/${id}/${status}`,
    method: 'put'
  })
}

// 删除商品
export const deleteItem = (id: number) => {
  return request({
    url: `/items/${id}`,
    method: 'delete'
  })
}

// 搜索商品
export const searchItems = (params: ItemPageQuery) => {
  return request({
    url: '/search/list',
    method: 'get',
    params
  })
} 